<template>
 <div>

    <el-table
      :data="userlist"
      style="width: 100%;"
      border
    >
      <el-table-column prop="id" label="日期" sortable width="180">
      </el-table-column>
      <el-table-column prop="username" label="姓名" sortable width="180">
      </el-table-column>
      <el-table-column prop="rolename" label="地址"> </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="item">
          <div>
            <el-tag v-if="item.row.status == 1" type="success">启动</el-tag>
            <el-tag v-else type="danger">禁用</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="item">
          <div>
            <el-button
              type="danger"
              icon="el-icon-delete"
              @click="del(item.row.uid)"
              circle
            ></el-button>
            <el-button type="primary" icon="el-icon-edit" @click="edit(item.row.uid)" circle></el-button>
            <el-button icon="el-icon-search" circle></el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      :page-size="size"
      background
      layout="prev, pager, next"
      :total="count"
      @current-change='changePage'
    >
    </el-pagination>
 </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import { userDel } from "../../util/request/api";
export default {
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      userlist: "user/getUserList",
      size: "user/getSize",
      count: "user/getCount",
    }),
  },
  mounted() {
    //组件一加载就获取菜单列表
    this.getUserList();
        this.getCount();
  },
  methods: {
    ...mapActions({
      getUserList: "user/getUserAction",
        getCount: "user/getCountAction",
      changePageAction:'user/changePageAction'
    }),
      changePage(n){
      console.log(n,'当前页');
      this.changePageAction(n)
    },
    cancel(e) {
      this.info.isshow = e;
    },
    edit(id) {
      this.$emit("edit", id);
    },
 del(uid) {
      this.$confirm("你确定要删除当前这条数据吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //调用删除接口
          userDel({ uid }).then((res) => {
            if (res.code == 200) {
              //删除成功，要重新调用接口列表(相当于重新触发行动)
              this.getUserList();
              //获取管理员总条数
              this.getCount();
              this.$message.success(res.msg);
            } else {
              this.$message.error(res.msg);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>

<style scoped>
.el-menu {
  margin: -20px;
  margin-bottom: 20px;
}
</style>